<template>
  <view class>
    <!-- 头部 -->
    <pagehead>实名</pagehead>
    <view class="warn">
        <view class="p">
          <image :src="IMAGE_STATIC+'/images/warn.png'" class="ico" mode="heightFix" />只能完善一次，并且需要与提现账号账户一致。</view>
        <view class="p"> <image :src="IMAGE_STATIC+'/images/warn.png'" class="ico" mode="heightFix" />如需修改请联系客服。</view>
      </view>
    <view class="form-warp">
      <view class="form-box">
        <!-- <view class="form-item" v-if="userInfo.phone">
						<view class="form-item-label">
							登录手机号
						</view>
						<view class="form-item-inner">{{userInfo.phone | conceal(4)}}</view>
        </view>-->
        <view class="form-item">
          <view class="form-item-label">姓名</view>
          <u--input
            class="form-item-inner"
            placeholder="请输入姓名"
            type="text"
            customStyle="marginLeft:40rpx;marginRight:40rpx;"
            border="none"
            v-model="form.name"
            :readonly="usermsg.real_name"
          ></u--input>
        </view>
        <view class="form-item">
          <view class="form-item-label">身份证号</view>
          <u--input
            class="form-item-inner"
            placeholder="请输入身份证号"
            type="text"
            customStyle="marginLeft:40rpx;marginRight:40rpx;"
            border="none"
            v-model="form.idCard"
            :readonly="usermsg.real_name"
          ></u--input>
        </view>
      </view>
      <view class="submit" v-if="!usermsg.real_name" @tap.stop="submit()">确定</view>
    </view>
  </view>
</template>

<script>
export default {
  data() {
    return {
      
      IMAGE_STATIC: this.$url.assetsPath,
      isSend: true,
      remain: "获取验证码",
      form: {
        name: "",
        idCard: ""
      },
      addstatus: false,
      usermsg: uni.getStorageSync("usermsg")
        ? uni.getStorageSync("usermsg")
        : { real_name: "" }
    };
  },
  onLoad() {
    if(this.usermsg.real_name){
      this.form.name = this.usermsg.real_name
      this.form.idCard = this.usermsg.id_card
    }
  },
  methods: {
    // 发送验证码
    sendCode() {
      if (this.isSend == true) {
        uni.showLoading({
          title: "发送中",
          mask: true
        });
        var data = {};
        this.phone = this.userInfo.phone;
        data["account"] = this.phone;
        data["validateType"] = 1;
        data["bizType"] = 4;
        // if(this.phone.indexOf("@") >-1){
        // 	data['type'] = 6;
        // }
        // if(this.phone.indexOf("@") <0){
        // 	data['type'] = 5;
        // }
        console.log("data：", data);
        this.$Ajax("/app/send/msgAuthCode", data, res => {
          this.isSend = false;
          this.remain = this.time + "s";
          this.uuid = res.data;
          this.timer = setInterval(() => {
            this.time--;
            this.remain = this.time + "s";
            if (this.time == 0) {
              clearInterval(this.timer);
              this.remain = "重新获取";
              (this.isSend = true), (this.time = 60);
            }
          }, 1000);
        });
        uni.hideLoading();
      }
    },
    submit() {
      let that = this;
      if (!that.form.name) {
        return that.$tools.toast("请输入姓名");
      }
      if (!that.form.idCard) {
        return that.$tools.toast("请输入身份证号");
      }
      var pattern = /^[1-9]\d{5}(18|19|20|21|22)?\d{2}(0[1-9]|1[0-2])(0[1-9]|[12]\d|3[01])\d{3}(\d|[Xx])$/;
      if (!pattern.test(that.form.idCard)) {
        return	that.$tools.toast('身份证号码有误');
      } 
      let userBankQo = {
        real_name: that.form.name,
        id_card: that.form.idCard
      };
      
      that.$Ajax("/api/user/setting/modifyUserInfo", userBankQo, res => {
        if (res.success) {
          that.$tools.toastBack(res.msg, 1);
          that.getUserInfo();
        }
      });
    }
  }
};
</script>

<style lang="scss" scoped>
@import "@/common/scss/operate";
.warn{
  overflow: hidden;
    width: 100%;
    margin: auto;
    padding: 16px 12px;
    font-size: 14px;
    background: #FFF5EF;
    color: #ED7B2F;
    .ico{
      display: inline-block;
      width: 32rpx;
      height: 32rpx;
      vertical-align: middle;
      margin-right: 10rpx;
    }
  .p{
    margin-top: 10rpx;
  }
}
</style>
